﻿#include<stdio.h>
#include<stdlib.h>

typedef struct ListNode
{
	int val;
	struct ListNode* next;
}ListNode,*pListNode;
bool hasCycle(pListNode head)
{
	pListNode fast = head;
	pListNode slow = head;
	while (fast && fast->next)
	{
		fast = fast->next->next;
		slow = slow->next;
		if (fast == slow)
		{
			return true;
		}
	}
	return false;
}
int main()
{
	pListNode head = (pListNode)malloc(sizeof(ListNode));
	head->val = 3;
	pListNode node1 = (pListNode)malloc(sizeof(ListNode));
	node1->val = 2;
	pListNode node2 = (pListNode)malloc(sizeof(ListNode));
	node2->val = 0;
	pListNode node3 = (pListNode)malloc(sizeof(ListNode));
	node3->val = 4;

	head->next = node1;
	node1->next = node2;
	node2->next = node3;
	node3->next = node1;
	bool ret = hasCycle(head);
	printf("%d", ret);

	return 0;
}